﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DefLib;
namespace GameUI
{
    public class Button:WindowUI
    {
        private int s_normal = 0;
        private int s_hover = 1;
        private int s_click = 2;

        int count = 0;
        public override event WindowUI.GetEvent Enter;

        public Button()
        {
        }
       
        public override void create(List<Sprite> lS_interface, float _x, float _y, int _w, int _h)
        {
            base.create(lS_interface, _x, _y, _w, _h);
        }
        public override void update(float x, float y, int w, int h)
        {

            bool a = false;
            if (sp_state.Count > 0)
                if (sp_state[0] == s_click)
                    if(Enter!=null)
                        a = true;

            if (a)
            {
                count++;
                if (count % 10 == 0)
                {
                    GetEvent handle = Enter;

                    if (handle != null)
                        handle(new DefLib.Event(), DefLib.gDef.now_gamestate);
                }
            }
            else
            {
                this.sp_index.Clear();
                this.sp_state.Clear();
                sp_index.Add(0);
                sp_index.Add(1);

                if (is_choise())
                {

                    sp_state.Add(s_click);


                }
                else
                    if (is_hover())
                    {
                        sp_state.Add(s_hover);
                    }
                    else
                    {
                        sp_state.Add(s_normal);
                    }
                sp_state.Add(0);
            }
                    base.update(x, y, w, h);
                
        }
    
    }
}
